/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pos.Driving.Dashboard.Image;

import javax.media.j3d.*;
import javax.vecmath.*;
import pos.utils.Invokeable;
import pos.utils.ObjectFactory;
import pos.utils.PathRes;
import pos.utils.Plane2D;

/**
 *
 * @author Administrator
 */
public class ControlPane extends TransformGroup implements Invokeable{
    private float fxStep;
    private double pow;
    private OrderedGroup ogPane;
    private Plane2D planeEB;
    private TransformGroup tgHandle, tgEB,tgDoorTips;

    public ControlPane(Transform3D transform) {
        super(transform);
        //this.setTransform(transform);
        this.setCapability(ALLOW_TRANSFORM_WRITE);
        initObjects();
        this.addChild(ogPane);
    }

    public void setPow(double pow) {
        this.pow = pow;
        float posY;
        planeEB.setAlpha(0);
        if (pow>0)      //push
            posY=0.09f+(float)pow*0.48f;
        else if (pow>-1.01)     //break
            posY=0.09f+(float)pow*0.55f;
        else{                    //EB
            if ((fxStep-(int)fxStep)>0.5)
                planeEB.setAlpha(0);
            else
                planeEB.setAlpha(1);
            posY=-0.46f;
        }
        Transform3D t3d=new Transform3D();
        t3d.set(new Vector3f(0.42f,posY,0.01f));
        tgHandle.setTransform(t3d);
    }
    
    @Override
    public void invoke(double Step) {
        fxStep=(fxStep+(float)Step) % 100f;
    }
    
    private void initObjects(){
        ogPane=new OrderedGroup();
        ogPane.addChild(ObjectFactory.createTexturedSurface(1.2f, 1.2f, 0,
                new Color3f(1f,1f,1f), 0.1f, 
                PathRes.getPath("Image.DriveRoom.AC03.HandleBack")));
        
        Transform3D t3d=new Transform3D();
        t3d.set(new Vector3f(0.42f,0.57f,0.01f));
        tgHandle=new TransformGroup(t3d);
        tgHandle.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        tgHandle.addChild(ObjectFactory.createTexturedSurface(0.35f, 0.24f, 0,
                new Color3f(1f,1f,1f), 0, 
                PathRes.getPath("Image.DriveRoom.AC03.Handle")));
        ogPane.addChild(tgHandle);
        
        t3d.set(new Vector3f(-3.22f,3.1f,0.01f));
        tgDoorTips=new TransformGroup(t3d);
        tgDoorTips.addChild(ObjectFactory.createTexturedSurface(0.6f, 0.6f, 0,
                new Color3f(1f,1f,1f), 0.1f, 
                PathRes.getPath("Image.DriveRoom.DoorTips")));
        ogPane.addChild(tgDoorTips);
        
        t3d.set(new Vector3f(-0.2f,-0.4f,0.01f));
        tgEB=new TransformGroup(t3d);
        planeEB=(Plane2D)ObjectFactory.createTexturedSurface(0.5f, 0.5f, 0,
                new Color3f(1f,1f,1f), 0, 
                PathRes.getPath("Image.DriveRoom.EBButton"));
        tgEB.addChild(planeEB);
        ogPane.addChild(tgEB);
    }
    //TempCode
    public void setVisualType(int type){
        Transform3D t3d=new Transform3D();
        switch (type){
            case 0:     //Forward View Show all
                t3d.set(new Vector3f(1.45f,-0.65f,-5f));
                break;

            case 1:     //Show Door Tips
           // case 4:
                t3d.set(new Vector3f(1.45f,-2.65f,-5f));
                break;

            case 2:     //Show Speed Meter
                t3d.set(new Vector3f(1.45f,-5.65f,-5f));
                break;

            default:    //Show nothing
                t3d.set(new Vector3f(1.45f,-10f,5f));
                break;
        }
        this.setTransform(t3d);
    }
}
